% Returns a string with only one space seperating fields.

function output_matrix = remspace(input_string)

if isempty(input_string)
output_matrix = [];
return
elseif size(input_string,1) > 1
'Input must be a string vector with 1 row !'
return
end

iip = findstr(input_string,char(32));
iiq = setdiff(1:length(input_string),iip);
iir = find(diff([iip 9999]) > 1);
iis = iip(iir);

output_matrix = input_string(sort([iiq iis])); % Location of spaces

output_matrix = deblank(output_matrix);
output_matrix = fliplr(deblank(fliplr(output_matrix)));